import java.io.PrintWriter;
import java.util.Scanner;

public class OptimalSolution {

	Scanner in;
	PrintWriter out;

	private int getDigitSum(long num) {
		int sum = 0;
		while (num > 0) {
			sum += num % 10;
			num /= 10;
		}
		return sum;
	}

	void solve() {
		int n = in.nextInt();
		int nTests = in.nextInt();
		int maxLen = n;
		int maxSum = maxLen * 9;
		long table[][] = new long[1 + maxSum][1 + maxLen];
		for (int curLen = 1; curLen <= maxLen; curLen++) {
			table[1][curLen] = 1;
		}
		for (int curSum = 1; curSum <= 9; curSum++) {
			table[curSum][1] = 1;
		}
		for (int curSum = 2; curSum <= maxSum; curSum++) {
			for (int curLen = 2; curLen <= maxLen; curLen++) {
				for (int dSum = 0; dSum <= 9; dSum++) {
					if (curSum - dSum >= 0) {
						table[curSum][curLen] += table[curSum - dSum][curLen - 1];
					}
				}
			}
		}
		for (int testNum = 0; testNum < nTests; testNum++) {
			long k = in.nextLong();
			int kLen = Long.toString(k).length();
			int kSum = getDigitSum(k);
			long ans = 0;
			if (kSum > 1) {
				ans++;
			}
			for (int curSum = 1; curSum < kSum; curSum++) {
				for (int curLen = kLen + 1; curLen <= maxLen; curLen++) {
					ans += table[curSum][curLen];
				}
			}
			out.println(ans);
		}
	}

	void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new OptimalSolution().run();
	}

}
